﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace Silvermoon.Controls.Classes
{
    public class GridUnitCollection : Collection<GridUnit>
    {
        private Control owner;

        public void AddRange(params GridUnit[] units)
        {
            foreach (GridUnit gu in units) Add(gu);
        }

        public GridUnitCollection(Control owner)
            : base()
        {
            this.owner = owner;
        }

        protected override void ClearItems()
        {
            base.ClearItems();
            InvalidateOwner();
        }

        protected override void InsertItem(int index, GridUnit item)
        {
            base.InsertItem(index, item);
            InvalidateOwner();
        }

        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);
            InvalidateOwner();
        }

        protected override void SetItem(int index, GridUnit item)
        {
            base.SetItem(index, item);
            InvalidateOwner();
        }

        private void InvalidateOwner()
        {
            owner.Invalidate(InvalidationFlag.Layout);
        }

    }
}
